import pandas as pd


def choose_roe(source_list,  comparison_operators, value):
    """
    选出roe符合的
    :param source_list:
    :param comparison_operators:  比较运算符 > < ==
    :param value: 比较的值
    :return:
    """
    if comparison_operators == '>':
        return source_list[source_list['roe'] > value]
    elif comparison_operators == '>=':
        return source_list[source_list['roe'] >= value]
    elif comparison_operators == '==':
        return source_list[source_list['roe'] == value]
    elif comparison_operators == '<':
        return source_list[source_list['roe'] < value]
    elif comparison_operators == '<=':
        return source_list[source_list['roe'] <= value]


def choose_inv_turn(source_list,  comparison_operators, value):
    """
    选出存货周转率符合的
    :param source_list:
    :param comparison_operators:  比较运算符 > < ==
    :param value: 比较的值
    :return:
    """
    if comparison_operators == '>':
        return source_list[(source_list['inventories']/ source_list['total_cur_assets']) > value]  # total_cur_assets：流动资产合计，inventories：存货
    elif comparison_operators == '>=':
        return source_list[(source_list['inventories']/ source_list['total_cur_assets']) >= value]
    elif comparison_operators == '==':
        return source_list[(source_list['inventories']/ source_list['total_cur_assets']) == value]
    elif comparison_operators == '<':
        return source_list[(source_list['inventories']/ source_list['total_cur_assets']) < value]
    elif comparison_operators == '<=':
        return source_list[(source_list['inventories']/ source_list['total_cur_assets']) <= value]



def choose_should_receive(source_list,  comparison_operators, value):
    """
    选出应收款周转率符合的
    :param source_list:
    :param comparison_operators:  比较运算符 > < ==
    :param value: 比较的值
    :return:
    """
    if comparison_operators == '>':
        # return source_list[(source_list['accounts_receiv']/ source_list['total_revenue']) > value]  # accounts_receiv：应收账款，total_revenue：总收入
        return source_list[source_list['ar_turn'] > value]  #ar_turn ：应收款周转率
    elif comparison_operators == '>=':
        return source_list[source_list['ar_turn'] > value]
    elif comparison_operators == '==':
        return source_list[source_list['ar_turn'] > value]
    elif comparison_operators == '<':
        return source_list[source_list['ar_turn'] > value]
    elif comparison_operators == '<=':
        return source_list[source_list['ar_turn'] > value]



def choose_debt_to_assets(source_list, comparison_operators, value):
    """
    选出资产负债率符合的
    :param source_list:
    :param comparison_operators:
    :param value:
    :return:
    """
    if comparison_operators == '>':
        return source_list[source_list['debt_to_assets'] > value]
    elif comparison_operators == '>=':
        return source_list[source_list['debt_to_assets'] >= value]
    elif comparison_operators == '==':
        return source_list[source_list['debt_to_assets'] == value]
    elif comparison_operators == '<':
        return source_list[source_list['debt_to_assets'] < value]
    elif comparison_operators == '<=':
        return source_list[source_list['debt_to_assets'] <= value]



def choose_pe_ttm(source_list, comparison_operators, value):
    """
    选出市盈率符合的
    :param source_list:
    :param comparison_operators:
    :param value:
    :return:
    """
    if comparison_operators == '>':
        return source_list[source_list['pe_ttm'] > value]
    elif comparison_operators == '>=':
        return source_list[source_list['pe_ttm'] >= value]
    elif comparison_operators == '==':
        return source_list[source_list['pe_ttm'] == value]
    elif comparison_operators == '<':
        return source_list[source_list['pe_ttm'] < value]
    elif comparison_operators == '<=':
        # print(source_list.loc[7])
        return source_list[source_list['pe_ttm'] <= value]





def choose_goodwill(source_list, comparison_operators, value):
    """
    选出商誉符合的
    :param source_list:
    :param comparison_operators:
    :param value:
    :return:
    """
    if comparison_operators == '>':
        return source_list[ ( source_list['goodwill'] / (source_list['total_mv'] *10000 / source_list['pb'])) > value]
    elif comparison_operators == '>=':
        return source_list[ ( source_list['goodwill'] / (source_list['total_mv'] *10000 / source_list['pb'])) >= value]
    elif comparison_operators == '==':
        return source_list[ ( source_list['goodwill'] / (source_list['total_mv'] *10000 / source_list['pb'])) == value]
    elif comparison_operators == '<':
        return source_list[ ( source_list['goodwill'] / (source_list['total_mv'] *10000 / source_list['pb'])) < value]
    elif comparison_operators == '<=':
        return source_list[ ( source_list['goodwill'] / (source_list['total_mv'] *10000 / source_list['pb'])) <= value]

